//
//  MSVisitorView.swift
//  weibo002
//
//  Created by mac on 10/19/15.
//  Copyright © 2015 mac. All rights reserved.
//

import UIKit
import SnapKit

class MSVisitorView: UIView {
    
    func setupViewInfo(title: String, imageName: String?){
        guard let img = imageName else{
            wheelsAnimation()
            return
        }
        titleLabel.text = title
        wheelsIconView.hidden = true
        mainIconView.image = UIImage(named: img)
        sendSubviewToBack(maskIconView)
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//    转轮
    private lazy var wheelsIconView: UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
//    遮罩图片
    private lazy var maskIconView: UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
//    主图片
    private lazy var mainIconView: UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
//    文字
    private lazy var titleLabel: UILabel = UILabel(title: "关注一些人，回这里看看有什么惊喜")
//    注册按钮
     lazy var signupButton: UIButton = UIButton(title: "注册", color: UIColor.orangeColor(), imageName: "common_button_white_disable")
//    登录按钮
     lazy var loginButton: UIButton = UIButton(title: "登录", color: UIColor.darkGrayColor(), imageName: "common_button_white_disable")
    
    private func wheelsAnimation(){
        let animation = CABasicAnimation()
        animation.keyPath = "transform.rotation"
        animation.toValue = 2 * M_PI
        animation.repeatCount = MAXFLOAT
        animation.removedOnCompletion = false
        animation.duration = 20
        wheelsIconView.layer.addAnimation(animation, forKey: nil)
    }
    

}

extension MSVisitorView{
    
    private func setupUI(){
        addSubview(wheelsIconView)
        addSubview(maskIconView)
        addSubview(mainIconView)
        addSubview(titleLabel)
        addSubview(signupButton)
        addSubview(loginButton)
        
//自动布局  
//        转轮
        wheelsIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-60)
        }
//        主图片
        mainIconView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(wheelsIconView.snp_center)
        }
//        文字
        titleLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(wheelsIconView.snp_centerX)
            make.top.equalTo(wheelsIconView.snp_bottom).offset(16)
            make.width.equalTo(224)
            make.height.equalTo(36)
        }
//        注册按钮
        signupButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(titleLabel.snp_left)
            make.top.equalTo(titleLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
//        登录按钮
        loginButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(titleLabel.snp_right)
            make.top.equalTo(titleLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
//        遮罩图片
        maskIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(signupButton.snp_bottom)
        }
        backgroundColor = UIColor(white: 237.0 / 255.0, alpha: 1.0)
        
    }
    
}
